<template>
	<view class="setting-all-wrap">
		
		<cu-custom bgColor="#ffffff" :isBack="true" textColor="#000000">
			<block slot="backText"></block>
			<block slot="content">设置</block>
		</cu-custom>
		
		<view class="touce-wrap">
			<view @click="updateversion" class="touce-item">
				<image class="search_home" src="../../static/black/update.png" style="width: 50rpx;height: 50rpx;position: relative;top: 15rpx;left: -6rpx;"></image>
				<text class="touch_txt">版本更新</text>
				<text class="iconfont icon-jinrujiantou c-more-icon set-num-txt"></text>
			</view>
			<view @click="clearcache" class="touce-item">
				<image class="search_home" src="../../static/black/clear.png" style="width: 50rpx;height: 50rpx;position: relative;top: 15rpx;left: -6rpx;"></image>
				<text class="touch_txt">缓存清除</text>
				<text class="iconfont icon-jinrujiantou c-more-icon set-num-txt"></text>
			</view>
		</view>
		
		<view @click="logout" class="logout-wrap">
			<text>退出登录</text>
		</view>
		
	</view>
</template>
<script>
	const app = getApp();
	export default {
		data() {
			return {
				CustomBar: this.CustomBar,
				StatusBar: this.StatusBar,
				theme: app.globalData.theme.backgroundColor, //全局颜色变量
				
				cacheSize: 0
			}
		},
		methods: {
			// 版本更新
			updateversion(){
				uni.showToast({
					icon: 'none',
					title: '已经是最新版本'
				});
			},
			// 获取清除的缓存
			getcache(){
				// #ifdef APP-PLUS
				var self = this;
				plus.cache.calculate(function(size) { //size是多少个字节单位是b
				    //做下面相应的处理
				    if (size < 1024) {
				        self.cacheSize = size + 'B';
				    } else if (size / 1024 >= 1 && size / 1024 / 1024 < 1) {
				        self.cacheSize = Math.floor(size / 1024 * 100) / 100 + 'KB';
				    } else if (size / 1024 / 1024 >= 1) {
				        self.cacheSize = Math.floor(size / 1024 / 1024 * 100) / 100 + 'M';
				    }
				});
				// #endif
			},
			// APP端清除缓存
			clearcache() {
			    // #ifdef APP-PLUS
			    var self = this;
			    //使用plus.cache.clear 清除应用中的缓存数据
			    plus.cache.clear();
			    // #endif
				uni.showToast({
				    title: '清除成功!',
				    icon: 'none',
				    success() {
				        self.cacheSize = '0B'
				    }
				});
			},
			// 退出账号
			logout(){
				app.globalData.userinfo.studentId = null;
				app.globalData.userinfo.userId = null;
				app.globalData.userinfo.llyId = null;
				app.globalData.userinfo.avatar = '';
				app.globalData.userinfo.user_nickname = '';
				app.globalData.userinfo.user_phoneNum = '';
				uni.removeStorage({
				    key: 'userinfo',
				    success: function (res) {
						uni.reLaunch({
							url: '../my/my',
						});
				    }
				});
			},
		}
	}
</script>
<style>
	page{
		background-color: #FFFFFF;
	}
	.setting-all-wrap {
		margin: 0 auto;
		border-top: 4rpx solid #E8E8E8;
	}
	.touce-wrap {
		height: 180rpx;
		margin: 0 auto;
		background-color: #FFFFFF;
	}
	.touce-item {
		height: 90rpx;
		line-height: 90rpx;
		padding-left: 21rpx;
		border-bottom: 2rpx solid #F5F5F5;
	}
	.touch_txt {
		display: inline-block;
		width: 75%;
		height: 100%;
		color: #000000;
		font-size: 30rpx;
	}
	.set-num-txt {
		display: inline-block;
		width: 15%;
		text-align: right;
	}
	/* 退出账号 */
	.logout-wrap {
		margin: 0 auto;
		width: 95%;
		height: 90rpx;
		line-height: 90rpx;
		margin-top: 20rpx;
		text-align: center;
		font-size: 30rpx;
		color: #FFFFFF;
		background-color: #3694EF;
		border-radius: 45rpx;
	}
</style>